<template>
	<view class="" style="background: #fff;">
		<view class="repair">
			<view class="uni-title" style="width: 30%;">申请人：</view>
			<view class="uni-title" style="width: 70%;">{{active.applicant}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">申请时间：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.costapp_time}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">公司部门：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.costapp_company}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">申请类型：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.costapp_status2}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">费用金额：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.costapp_amount}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">金额(大写)：</view>
			<view class="uni-title" style="width: 70%;">{{big_costapp_amount}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">申请事项：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.costapp_appitem}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">审批意见：</view>
			<textarea class="uni-title" style="width: 70%;height: 70upx;" v-model="reasons" placeholder="请填写意见" />
		</view>
		<view class="repair" v-if="user!==''">
			<view class="uni-title" style="width: 30%;">下一审批人：</view>
				<view class="uni-list-cell-db">
					<picker-c @change="handleApprover" :aList="aList"></picker-c>
				</view>
		</view>
		<template v-for="(item, index) in buttonList">
						<button v-if="item == 'submit'" type="primary" class="btn" @click="Approvalclick(true)">提交</button>
						<button v-if="item == 'Resubmit'" type="primary" class="btn" @click="Approvalclick(true)">重新提交</button>
		                <button v-if="item == 'reject'" type="warn" class="btn" @click="Approvalclick(false)">驳回</button>
						<button v-if="item == 'disagree'" type="error" class="btn" @click="Approvalclick('finish')">不同意</button>
		              </template>
	</view>
</template>

<script>
	import {number_chinese} from "../../../common/global-fn.js"
	import {apipassField,apigetProcessList,apigetCostappById} from '@/common/api.js'
	export default{
		name:'Approval',
		data(){
			return{
				Fielddata:[],
				active:{},
				reasons:'',
				id:'',
				applyType: ["费用审批", "借支申请", "报销申请"],
				user:'',
				aList:[],
				buttonList:[],
			}
		},
		onLoad(e){
			this.active=JSON.parse(e.active)
			this.id=this.active.BUSINESS_KEY_.split('.')[1]
			console.log(this.id)
			//获取外勤单的数据
			apigetCostappById({costapp_id:this.id}).then(res=>{
				console.log(res)
				this.Fielddata=res.data.data
				this.Fielddata.costapp_status2=this.applyType[this.Fielddata.costapp_status]
				this.hisComment=res.data.hisComment
				console.log(this.hisComment)
			})
			this.getpress()
		},
		computed:{
			big_costapp_amount(){
				return number_chinese(this.Fielddata.costapp_amount)
			}
		},
		created(){
			
		},
		methods:{
			getpress(){
				let data={
					taskid: this.active.ID_, //(必填)流程任务id
				    processInstanceId: this.active.PROC_INST_ID_, //(必填)流程实例id
				    key: "costappView", //(必填)流程定义key
				    position: this.active.role_name, //(必填)申请人角色
				    type: "" //(必填)新增new/运行中
					}
					console.log(JSON.stringify(data))
				apigetProcessList(data).then(res=>{
					console.log(res)
					this.buttonList=res.data.startForm.split(",")
					let userTaskName = res.data.userlist.userTaskName;
					this.aList=res.data.userlist.userList?res.data.userlist.userList:[]
					this.user=userTaskName === "结束"?0:this.aList&&this.aList!=""?this.aList[0]:""
				})
			},
			handleApprover(e){
				this.user = e
			},
			Approvalclick(sign){
				if(this.user===""){
					this.toast('审核人为空不能提交！')
					return
				}
				if(this.reasons===""){
					this.toast('请填写审核意见！')
					return
				}
				let data={
					"taskid":this.id,
					"userid":this.user.userid,
					"reasons":this.reasons,
					"sign":sign
				}
				console.log(data)
				uni.showModal({
					content:'确定提交吗？'
				}).then(res=>{
					if(res[1].confirm){
				apipassField(data).then(res=>{
					// console.log(res)
					// let msg="已审批通过"
					// if(sign=="false"){
					// 	msg="已驳回"
					// }
					if(res.data){
						this.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack({
								delta:2
							})
						},1200)
					}
				})
				}else{
					console.log('取消')
				}
				})
			},
			toast(title,icon='none'){
				uni.showToast({
					title: title,
					mask: true,
					icon:icon,
					duration: 1500
				});
			}
		}
	}
</script>

<style scoped>
	.repair{
		display: flex;
		align-items:center;
		padding: 20upx 30upx;
		box-sizing:border-box;
		border-bottom: 1px solid #eee;
	}
	.btn{
		margin: 30upx;
	}
</style>
